package com.atjinggu.jinggumail.search.controller;

import com.atjinggu.jinggumail.common.enums.BizCodeEnum;
import com.atjinggu.jinggumail.common.to.es.SkuEsModule;
import com.atjinggu.jinggumail.common.utils.R;
import com.atjinggu.jinggumail.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jingming
 * @Type ElasticSaveController.java
 * @Desc
 * @date 2021/1/8 12:11
 */
@RequestMapping("/search")
@RestController
@Slf4j
public class ElasticSaveController {

    @Autowired
    ProductSaveService productSaveService;

    //商品上架
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModule> esModuleList){
        boolean b = false;
        try {
             b = productSaveService.productStatusUp(esModuleList);
        }catch (Exception e){
            log.error("商品上架失败{}",e);
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
        if(b){
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }else {
            return R.ok();
        }


    }
}